package com.dao.impl;

import com.dao.StudentDao;
import com.entity.Student;
import com.mapper.StudentMapper;
import com.page.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository("studentDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class StudentDaoImpl implements StudentDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private StudentMapper studentMapper;
    public List<Student>  getAllStudents() throws Exception{
        return studentMapper.selectByExample(null);
    }

    @Override
    public Student selectStudentBySno(String sno) throws Exception {
        return studentMapper.selectByPrimaryKey(sno);
    }

    @Override
    public Student getAccountByAccountName(String name) throws Exception {
        return studentMapper.getAccountByAccountName(name);
    }



    public Student selectBySnoWithScs(String sno) throws Exception{
        return studentMapper.selectBySnoWithScs(sno);
    }

    @Override
    public Student selectBySnoWithClazz(String sno) throws Exception {
        return studentMapper.selectBySnoWithClazz(sno);
    }

    @Override
    public Student selectBySnoWithClazzANDTeacher(String sno) throws Exception{
        return studentMapper.selectBySnoWithClazzANDTeacher(sno);
    }

    @Override
    public Student selectBySnoWithScsAndClazz(String sno) {
        return studentMapper.selectBySnoWithScsAndClazz(sno);
    }
    @Override
    public Student selectBySnoWithScsAndCourse(String sno){
        return studentMapper.selectBySnoWithScsAndCourse(sno);
    }

    @Override
    public Integer deleteStudentBySno(String sno) {
        return studentMapper.deleteByPrimaryKey(sno);
    }

    @Override
    public Integer updateStudentBySno(Student student) {
        return studentMapper.updateByPrimaryKey(student);
    }

    @Override
    public Integer addStudentBySno(Student student) {
        return studentMapper.insertSelective(student);
    }

}